/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-06 17:36:29
 * @LastEditors: 赵大壮
 */
import nyMessageToast from "@/utils/NYMessageToast";
import { Component, Vue, Inject, Watch } from "vue-property-decorator";
import DZServiceExport from "../../service/DZServiceExport";

@Component({
    components: {}
})
export default class Index extends Vue {

    s_export = new DZServiceExport();

    created() {
        this.s_export.m_export.id = (this.$route.query.id as string)
        this.s_export.net_list_dic();
        if (this.s_export.m_export.id) {
            this.s_export.net_info_export();
        }
    }

    mounted() {

    }

    beforeDestroy() {

    }

    action_select_heard(file) {
        if (file.status == "ready") {
            this.s_export.net_upload_image(file.raw, data => {
                this.s_export.m_export.heard = data;
                this.s_export.m_export.heard_url = URL.createObjectURL(file.raw);
            }, () => {
            });
        }
    }

    action_add_list(item) {
        if (item.start.nyIsEmpty() || item.end.nyIsEmpty()) {
            nyMessageToast.warning("请选择时间")
            return;
        }
        this.s_export.m_export.time_list.push({ start: '', end: '' })

    }

    action_splice_list(index) {
        this.s_export.m_export.time_list.splice(index, 1);
    }


    quickSort(arr) {
        if (arr.length <= 1) { // 长度小于等于1 返回自己
            return arr
        }
        let centerIndex = Math.floor(arr.length / 2) // 中间index
        let centerData = arr.splice(centerIndex, 1)[0] // 中间index 对应的 之，并从arr中剔除
        let letArry = []
        let rightArry = []
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] < centerData) { // 小于中间值放左数组 否则放右数组
                letArry.push(arr[i])
            } else {
                rightArry.push(arr[i])
            }
        }
        return this.quickSort(letArry).concat([centerData], this.quickSort(rightArry)) // 左数组快排后和中间值，右数组拼接
    }

    action_edit_export() {
        if (!this.s_export.m_export.heard) {
            nyMessageToast.error("请上传咨询师照片");
            return;
        }
        if (this.s_export.m_export.introduce.nyIsEmpty()) {
            nyMessageToast.error("请填写专家介绍");
            return;
        }
        if (this.s_export.m_export.target_list.length == 0) {
            nyMessageToast.error("请选择咨询对象");
            return;
        }
        this.s_export.m_export.target = this.s_export.m_export.target_list.join(",");
        if (this.s_export.m_export.theme_list.length == 0) {
            nyMessageToast.error("请选择咨询主题");
            return;
        }
        this.s_export.m_export.theme = this.s_export.m_export.theme_list.join(",");
        if (this.s_export.m_export.field_list.length == 0) {
            nyMessageToast.error("请选择擅长疗法");
            return;
        }
        this.s_export.m_export.field = this.s_export.m_export.field_list.join(",");
        if (this.s_export.m_export.experience.nyIsEmpty()) {
            nyMessageToast.error("请填写受训经历");
            return;
        }
        if (this.s_export.m_export.qualifications.nyIsEmpty()) {
            nyMessageToast.error("请填写资历资质");
            return;
        }
        if (this.s_export.m_export.week_list.length == 0) {
            nyMessageToast.error("请选择咨询日期");
            return;
        }
        this.s_export.m_export.week = this.quickSort(this.s_export.m_export.week_list).join(",");
        if (this.s_export.m_export.time_list[this.s_export.m_export.time_list.length - 1].start.nyIsEmpty()) {
            nyMessageToast.error("请选择咨询时间");
            return;
        }
        this.s_export.m_export.time = JSON.stringify(this.s_export.m_export.time_list);
        this.$delete(this.s_export.m_export, 'target_list')
        this.$delete(this.s_export.m_export, 'field_list')
        this.$delete(this.s_export.m_export, 'theme_list')
        this.$delete(this.s_export.m_export, 'time_list')
        this.$delete(this.s_export.m_export, 'week_list')
        this.s_export.net_edit_export(() => {
            this.$router.back();
        })
    }
}